using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Bars : MonoBehaviour
{
    public Image HealthBlock;
    public Image EffectBlock;
    public float EffectSpeed;
    private bool Running = false;
    public void LateUpdate(){
        HealthBarSetup();
        if(!Running){
            StartCoroutine(EffectSetup());
        }
    }
    void HealthBarSetup(){
        HealthBlock.fillAmount = ((float)PlayerCtrollor.PlayerAttribute.Health / (float)PlayerCtrollor.PlayerAttribute.MaxHealth);
    }
    IEnumerator EffectSetup(){
        if(EffectBlock.fillAmount <= HealthBlock.fillAmount){
            EffectBlock.fillAmount = HealthBlock.fillAmount;
            Running = false;
            yield return 0;
        }
        else{
            Running = true;
            yield return new WaitForSeconds(0.01f);
            EffectBlock.fillAmount -= EffectSpeed;
            StartCoroutine(EffectSetup());
        }
    }
}
